package com.transaction.exams;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;

import com.classapp.db.exam.CompExam;
import com.classapp.db.exam.ExamDB;
import com.classapp.db.exams.MCQData;
import com.classapp.db.exams.MCQDataDB;
import com.classapp.db.question.QuestionbankDB;
import com.datalayer.exambean.ExamData;


public class ExamTransaction {
	
	public void saveExam(ExamData examData) {
		MCQDataDB mcqDataDB = new MCQDataDB();
		MCQData mcqData = new MCQData();
		try {
			BeanUtils.copyProperties(mcqData, examData);
			mcqDataDB.updateDb(mcqData);
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
	}
	
	public List<com.datalayer.exam.MCQData> searchExamData(int classId,Date startDate,Date endDate,Integer divId,Boolean publish,Integer subjectId,Integer teacherId,Integer examId,String batch){
		MCQDataDB mcqDataDB = new MCQDataDB();
		 //mcqData = new com.datalayer.exam.MCQData();
		List<com.datalayer.exam.MCQData> mcqData = new ArrayList<com.datalayer.exam.MCQData>();
		List<MCQData> examData = mcqDataDB.searchExam(classId, startDate, endDate, divId, publish, subjectId, teacherId, examId,batch);
		for (MCQData data:examData) {
			com.datalayer.exam.MCQData mcqDataDest = new com.datalayer.exam.MCQData();
			try {
				BeanUtils.copyProperties(mcqDataDest, data);
				mcqData.add(mcqDataDest);
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return mcqData;
	}
	
	public List<CompExam> getAllCompExamList() {
		ExamDB db=new ExamDB();
		QuestionbankDB db2=new QuestionbankDB();
		return db.getAllCompExam();
	}
	
	
	public static void main(String[] args) {
		/*
		ExamData examData = new ExamData();
		examData.setClass_id(3);
		examData.setCreate_date(new Date());
		examData.setDiv_id(28);
		examData.setPublish(false);
		examData.setSubject_id(22);
		examData.setTeacher_id(10);
		examData.setUpload_path("");
		ExamTransaction examTransaction = new ExamTransaction();
		examTransaction.saveExam(examData);
		*/
		String batch  = "2";
		String[] str = batch.split(",");
		System.out.println();
		ExamTransaction examTransaction = new ExamTransaction();
		List list = examTransaction.searchExamData(3, null, null, null, null, null, null, null,"%2%");
		System.out.println(list);
	}
}
